package com.gqj.elec.controller;

import com.github.pagehelper.PageHelper;
import com.gqj.common.core.controller.BaseController;
import com.gqj.common.core.domain.AjaxResult;
import com.gqj.common.utils.StringUtils;
import com.gqj.elec.domain.ElecMaterial;
import com.gqj.elec.service.IElecMaterialOutdetailService;
import com.gqj.elec.service.IElecMaterialService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 接口Controller
 *
 * @author lxq
 * @date 2023-12-18
 */
@RestController
@RequestMapping("/elec/elecInterface")
public class ElecInterfaceController extends BaseController {
    @Autowired
    private IElecMaterialService elecMaterialService;
    @Autowired
    private IElecMaterialOutdetailService elecMaterialOutdetailService;
    /**
     * 查询物资列表
     */
    @PostMapping("/selectElecMaterialList")
    public AjaxResult selectElecMaterialList(@RequestBody ElecMaterial elecMaterial) {
        PageHelper.startPage(elecMaterial.getPageNum(), elecMaterial.getPageSize());
        elecMaterial.setDelFlag("0");
        List<ElecMaterial> list = elecMaterialService.selectElecMaterialList(elecMaterial);
        return AjaxResult.success(list);
    }


    /**
     * 查询物资列表
     */
    @GetMapping("/selectElecMaterialByRfidCode")
    public AjaxResult selectElecMaterialByRfidCode(@RequestParam("rfidCode") String rfidCode) {
        ElecMaterial  elecMaterial= elecMaterialService.selectElecMaterialByRfidCode(rfidCode);
        return AjaxResult.success(elecMaterial);
    }

    /**
     * 手持机发卡
     */
    @PostMapping("/saveRfidCode")
    public AjaxResult saveRfidCode(@RequestBody ElecMaterial elecMaterial) {
        //判断物资id和标签号是否为空
        if (null==elecMaterial.getMaterialId()){
            return AjaxResult.error("工器具标识为空，请检查重试！");
        }
        if(StringUtils.isEmpty(elecMaterial.getRfidCode())){
            return AjaxResult.error("标签号为空，请检查重试！");
        }
        return toAjax(elecMaterialService.updateElecMaterial(elecMaterial));
    }

    /**
     * 推送消息测试
     */
    @GetMapping("/test")
    public AjaxResult test() {
        return AjaxResult.success(elecMaterialOutdetailService.analysisTdm("123", 1));
    }
}
